import re
import os
import fnmatch

PYTHON_SRC_PATTERN = re.compile(fnmatch.translate(r'*.py'))

def iter_sources(path, walker, pattern=PYTHON_SRC_PATTERN):
    for p, ds, fs in walker(os.path.curdir):
        # Skip hidden directory
        ds[:] = [dn for dn in ds if not dn.startswith('.')]
        for fn in fs:
            if pattern.search(fn):
                yield p, fn

def mtimes(path, walker=os.walk, statfn=os.stat, pattern=PYTHON_SRC_PATTERN):
    def _iter_mtimes():
        for p, fn in iter_sources(path, walker, pattern):
            fp = os.path.join(p, fn)
            try:
                yield fp, statfn(fp).st_mtime
            except OSError:
                pass
    return set(_iter_mtimes())
